const LOCAL_KEY_PROJECT_FORM = "projectFormEdit";

const getDefaultState = () => ({
  projectFormEdit:
    JSON.parse(localStorage.getItem(LOCAL_KEY_PROJECT_FORM)) || {},
});

const state = getDefaultState();

const mutations = {
  SET_PROJECT_FORM: (state, payload) => {
    localStorage.setItem(LOCAL_KEY_PROJECT_FORM, JSON.stringify(payload));
    state.projectFormEdit = payload;
  },
};

const actions = {
  setProjectForm({ commit }, payload) {
    commit("SET_PROJECT_FORM", payload);
  },
  resetProjectForm({ commit }) {
    localStorage.removeItem(LOCAL_KEY_PROJECT_FORM);
    commit("SET_PROJECT_FORM", getDefaultState().projectFormEdit);
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
